<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="关键字搜索" prop="search">
        <el-input v-model="queryParams.search" placeholder="请输入关键字搜索" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="userName" />
      <el-table-column label="头像" align="center" prop="userPhoto">
        <template slot-scope="scope">
          <el-avatar :src="scope.row.userPhoto" />
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="sex">
        <template slot-scope="scope">
          <span>{{ scope.row.status == 0 ? '待审核' : scope.row.identity == 1 ? '通过' : scope.row.identity == 2 ? '拒绝' :
            '无' }}</span>
        </template>
      </el-table-column>

      <el-table-column label="拒绝原因" align="center" prop="refuseMemo" />

      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button size="mini" type="text"  @click="handleUpdate(scope.row, 1)"
            v-hasPermi="['system:anchor:check']">通过</el-button>
          <el-button size="mini" type="text"  @click="handleUpdate(scope.row,2)"
            v-hasPermi="['system:anchor:check']">拒绝</el-button>


        </template>

      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.size"
      @pagination="getList" />



    <el-dialog :title="'主持申请审核'" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="180px">

        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status">
            <el-option label="通过" :value="1"></el-option>
            <el-option label="拒绝" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="拒绝原因" prop="refuseMemo" v-if="form.status==2">
          <el-input v-model="form.refuseMemo" placeholder="请输入拒绝原因" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { anchorCheckList, anchorCheck } from "@/api/user/user";

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房间表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        page: 1,
        size: 10,
        search: '',
        startTime: '',
        endTiime: '',
        status: 0
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    uploadSuccess(res) {
      this.form.photo = res;
      console.log("图片上传.....", res)
    },
    /** 查询房间列表 */
    getList() {
      if (this.dateRange) {
        this.queryParams.startTime = this.dateRange[0];
        this.queryParams.endTiime = this.dateRange[1];
      }
      this.loading = true;
      anchorCheckList(this.queryParams).then(response => {
        this.userList = response.data.data;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        age: null,
        photo: null,
        nickName: null,
        imUsername: null,
        phone: null,
        backgroundUrl: null,
        sex: null,
        identity: null,
        isAuth: null,
        province: null,
        personalityName: null,
        interestHobby: null,
        placeServer: null,
        isDel: null,
        remark: null,
        updateTime: null,
        createTime: null,
        loginTime: null,
        logoutTime: null,
        photoWall: null,
        salt: null,
        password: null,
        openId: null,
        status: null,
        cardNum: null,
        isAdolescent: null,
        tutelageWord: null,
        tutelageSalt: null,
        rongToken: null,
        roomNumber: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加房间";
    },
    /** 修改按钮操作 */
    handleUpdate(row, status) {
      this.form.id=row.id;
      this.form.status=status;
      this.open=true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            anchorCheck(this.form).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除房间编号为"' + ids + '"的数据项？').then(function () {
        return delUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('user/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
